/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.application.commands;

import com.nanosn.coffeemaker.Project;
import com.nanosn.util.parsers.commandline.Argument;
import com.nanosn.util.parsers.commandline.Command;
import java.io.File;

/**
 *
 * @author selkhateeb
 */
@Argument(RegularExpression = "(startapp|sa)")
public class StartApplication implements Command {

    private String getApplicationName(String[] args) throws Exception {
        if (args.length < 2) {
            throw new Exception();
        }
        return args[1].toLowerCase();
    }

    public void run(String[] args) throws Exception {

        String rootPackage = Project.getSettings().getRootPackage();
        String rootPackageDirectory = Project.getDevelopmentDirectory() + rootPackage.replace(".", File.separator);
        File appDirectories = new File(rootPackageDirectory, getApplicationName(args));
        appDirectories.mkdirs();
        File modelsDirectories = new File(appDirectories, "models");
        modelsDirectories.mkdirs();
        File viewsDirectories = new File(appDirectories, "views");
        viewsDirectories.mkdirs();
        File testsDirectories = new File(appDirectories, "tests");
        testsDirectories.mkdirs();
    }

    public String getHelp() {
        return "Creates new applicaiton with neme ${value}";
    }
}
